home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 January: Mac OS SDK / Dev.CD Jan 96 SDK / Dev.CD Jan 96 SDK1.toast / Development Kits (Disc 1) / AOCE / Development Tools / Sample Code / Catalog Service Access Module / DTS Sample CSAM / Src / AddCatalog.c next >
Encoding:
C/C++ Source or Header  |  1993-08-27  |  3.6 KB  |  124 lines  |  [TEXT/KAHL]

  1. /*                                    AddCatalog.c                                */
  2. /*
  3.  * AddCatalog.c
  4.  * Copyright © 1992-93 Apple Computer Inc. All Rights Reserved.
  5.  *
  6.  * Add a catalog (expressed as a FSSpec) to our private list of catalogs. Note
  7.  * that AddCatalog allocates memory and, hence, must not be called from an I/O
  8.  * completion or interrupt routine.
  9.  */
  10. #include "DTSSampleCSAM.h"
  11.  
  12. OSErr
  13. AddCatalog(
  14.         register DTSSampleCSAMInfoPtr    infoPtr,
  15.         DirParamBlockPtr                pb
  16.     )
  17. {
  18.         OSErr                    status;
  19.         CatalogInfoPtr            newCatalog;
  20.         RecordID                rid;
  21.         short                    setupRefNum;
  22.         short                    pabRefNum;
  23.         FSSpec                    pabSpec;
  24.         AttributeType            attributeType;
  25.         AuthGetLocalIdentityPB    authParamBlock;
  26. #define ADD    (pb->addDSAMDirectoryPB)
  27. #define NEW    (*newCatalog)
  28.  
  29.         LogText('AddS', "\pAddCatalog entry");
  30.         LogRString('AddD', ADD.directoryName);
  31.         status = ADASGetOCESetupInfo(&rid, &setupRefNum);
  32.         LogStatus('AddD', status, "\pADASGetOCESetupInfo");
  33.         if (status == noErr) {
  34.             /*
  35.              * This couldn't be stored in a resource, for some bizarre
  36.              * reason. Perhaps the code hadn't setup the current resource
  37.              * file correctly.
  38.              */
  39.             OCECToRString(
  40.                 kPDAliasAttrTypeBody,            /* Note: C-string        */
  41.                 smRoman,
  42.                 (RStringPtr) &attributeType,
  43.                 kAttributeTypeMaxBytes
  44.             );
  45.         }
  46.         if (status == noErr) {
  47.             rid.local.recordName = NULL;
  48.             rid.local.recordType = NULL;
  49.             rid.rli = NULL;
  50.             OCECopyCreationID(&ADD.directoryRecordCID, &rid.local.cid);
  51.             pabSpec.vRefNum = 0;
  52.             /*
  53.              * Get the local identity. If this fails, use zero (guest).
  54.              */
  55.             (void) AuthGetLocalIdentity(
  56.                         (AuthParamBlockPtr) &authParamBlock,
  57.                         FALSE                /* Synchronous        */
  58.                     );
  59.             LogStatus('AddD', authParamBlock.ioResult, "\pAuthGetLocalIdentity");
  60.             if (authParamBlock.ioResult != noErr)
  61.                 authParamBlock.theLocalIdentity = 0;    /* Use "guest"         */
  62.             status = ADASLookupAttributeValue(
  63.                         &rid, 
  64.                         setupRefNum, 
  65.                         authParamBlock.theLocalIdentity, /* Use owner ident    */
  66.                         kAliasBufferSize,
  67.                         FALSE,                         /* Don't include start     */
  68.                         &attributeType,
  69.                         OCENullCID(),
  70.                         (long) &pabSpec,
  71.                         (ForEachAttrValue) GetPABFSSpecCB
  72.                     );
  73.             LogStatus('AddD', status, "\pADASLookupAttributeValue");
  74.         }
  75.         if (status == noErr) {
  76. LogText('AddD', "\pCalling ADASOpenPAB");
  77.             status = ADASOpenPAB(
  78.                         &pabSpec,
  79.                         fsRdWrPerm,
  80.                         &pabRefNum
  81.                     );
  82.             LogStatus('AddD', status, "\pADASOpenPAB");
  83.         }
  84.         if (status == noErr) {
  85.             /*
  86.              * The new catalog used to be created on the current heap. I changed
  87.              * this to creating it on the system heap because I'm paranoid about
  88.              * heap trashing.
  89.              */
  90.             newCatalog = (CatalogInfoPtr) NewPtrSysClear(sizeof (CatalogInfo));
  91.             status = MemError();
  92.             LogError('AddD', status);
  93.             if (status == noErr) {
  94.                 NEW.refNum = pabRefNum;
  95.                 OCECopyCreationID(&ADD.directoryRecordCID, &NEW.creationID);
  96.                 OCECopyDirDiscriminator(&ADD.discriminator, &NEW.discriminator);
  97.                 OCECopyRString(
  98.                     (RString *) ADD.directoryName,
  99.                     (RString *) &NEW.directoryName,
  100.                     kDirectoryNameMaxBytes
  101.                 );
  102.                 /*
  103.                  * Finally, add this catalog to the list of active catalogs. We
  104.                  * really don't need an operating system queue here, but Enqueue
  105.                  * does what we want and doesn't do what we don't want.
  106.                  */
  107.                 Enqueue((QElemPtr) newCatalog, &INFO.catalogQHdr);
  108.             }
  109.             else {
  110.                 /*
  111.                  * We couldn't allocate memory for this catalog. All we can do is
  112.                  * close the PAB. Ignore any error from ADASClosePAB since we
  113.                  * have a real error now.
  114.                  */ 
  115.                 (void) ADASClosePAB(pabRefNum);
  116.             }
  117.         }
  118.  
  119.         LogStatus('AddD', status, "\pAddCatalog exit");
  120.         LogRString('AdXt', ADD.directoryName);
  121.         return (status);
  122. #undef ADD
  123. }
  124.